package com.yunzheng.studyLeaveSystem.modules.user.user_info.service;

import com.yunzheng.studyLeaveSystem.modules.response.ResponseWrapper;
import com.yunzheng.studyLeaveSystem.modules.user.user_info.dao.User_infoDao;
import com.yunzheng.studyLeaveSystem.modules.user.user_info.entity.User_info;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: YunZheng
 * @Date: 2023/01/30/19:04
 * @Description:
 */
public class User_infoService {
    private User_infoDao user_infoDao = new User_infoDao();

    /**
     * 通过id查询用户信息
     *
     * @param id
     * @return
     */
    public User_info getUser_info(int id) throws Exception {
        return user_infoDao.getUser_info(id);
    }

    /**
     * 修改密码
     *
     * @param password1
     * @param password2
     * @param password3
     * @param id
     * @return
     * @throws Exception
     */
    public ResponseWrapper updatePassword(String password1, String password2, String password3, int id) throws Exception {
        ResponseWrapper responseWrapper = null;
        //原密码错误
        if (!(user_infoDao.queryPassword(id).equals(password1))) {
            responseWrapper = ResponseWrapper.Error1();
            return responseWrapper;
        }
        //修改密码不一致
        if (!(password2.equals(password3))) {
            responseWrapper = ResponseWrapper.Error2();
            return responseWrapper;
        }
        //修改成功
        user_infoDao.updatePassword(password2, id);
        responseWrapper = ResponseWrapper.SuccessButNoData();
        return responseWrapper;
    }

    /**
     * 修改手机号
     *
     * @param phone_num
     * @param phone_num1
     * @param phone_num2
     * @param phone_num3
     * @return
     * @throws Exception
     */
    public ResponseWrapper updatePhone_num(String phone_num, String phone_num1, String phone_num2, String phone_num3) throws Exception {
        ResponseWrapper responseWrapper = null;
        //原手机号错误
        if (!(phone_num.equals(phone_num1))) {
            responseWrapper = ResponseWrapper.Error3();
            return responseWrapper;
        }
        //修改手机号不一致
        if (!(phone_num2.equals(phone_num3))) {
            responseWrapper = ResponseWrapper.Error4();
            return responseWrapper;
        }
        //修改成功
        user_infoDao.updatePhone_num(phone_num2, phone_num);
        responseWrapper = ResponseWrapper.SuccessButNoData();
        return responseWrapper;
    }

    /**
     * 修改个人信息
     * @param username
     * @param gender
     * @param term
     * @param direction
     * @param constellation
     * @param hometown
     * @param phone_num
     * @param birthday
     * @param QQ
     * @param wechat
     * @param email
     * @param signature
     * @param id
     * @return
     * @throws Exception
     */
    public ResponseWrapper updateUser_info(String username, String gender, String term, String direction, String constellation, String hometown, String phone_num, String birthday, String QQ, String wechat, String email, String signature, int id) throws Exception {
        user_infoDao.updateUser_info(username, gender, term, direction, constellation, hometown, phone_num, birthday, QQ, wechat, email, signature, id);
        ResponseWrapper responseWrapper = ResponseWrapper.SuccessButNoData();
        return responseWrapper;
    }

    /**
     * 查询头像信息
     * @param id
     * @return
     * @throws Exception
     */
    public String query(int id) throws Exception {
        return user_infoDao.query(id);
    }
}



